package leetcode.code0985;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	public int[] sumEvenAfterQueries(int[] nums, int[][] queries) {
		int sum = 0;
		for (int num : nums) {
			if ((num & 1) == 0) {
				sum += num;
			}
		}
		int[] ans = new int[queries.length];
		for (int i = 0; i < queries.length; i++) {
			int[] query = queries[i];
			int val = query[0], index = query[1];
			int num = nums[index];
			if ((num & 1) == 0) {
				sum -= num;
			}
			num += val;
			if ((num & 1) == 0) {
				sum += num;
			}
			ans[i] = sum;
			nums[index] = num;
		}
		return ans;
	}

	@Override
	public void debug4() {
		H.compare(H.str2array3("[8,6,2,4]"),
				this.sumEvenAfterQueries(H.str2array3("[1,2,3,4]"), H.str2array1("[[1,0],[-3,1],[-4,0],[2,3]]")));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
